package src.com.neusoft.nep;

import src.com.neusoft.nep.entity.User;

import java.io.*;
import java.util.Map;

public class ReadFile {
    public static void main(String[] args) {
        File file = new File("PublicSupervisor.txt");
        if (!file.exists() || file.length() == 0) {
            System.out.println("文件不存在或为空");
            return;
        }

        try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file))) {
            // 读取 HashMap 对象
            Map<String, User> userMap = (Map<String, User>) ois.readObject();

            // 遍历并打印用户信息
            for (Map.Entry<String, User> entry : userMap.entrySet()) {
                String phoneNumber = entry.getKey();
                User user = entry.getValue();
                System.out.println("手机号: " + phoneNumber);
                System.out.println("密码: " + user.getPassword());
                System.out.println("确认密码: " + user.getRepassword());
                System.out.println("角色: " + user.getGender());
            }
        } catch (IOException | ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}